import collections
class Leaderboard(object):

    def __init__(self):
        self.stack = []

    def addScore(self, playerId, score):
        """
        :type playerId: int
        :type score: int
        :rtype: None
        """
        i = 0
        while i < len(self.stack):
            if self.stack[i][0] == playerId:
                score = score + self.stack[i][1]
                del self.stack[i]
                break
            i += 1
        flag = False
        i = 0
        while i < len(self.stack):
            if score >= self.stack[i][1]:
                self.stack.insert(i, [playerId, score])
                flag = True
                break
            i += 1
        if not flag:
            self.stack.append([playerId, score])



    def top(self, K):
        """
        :type K: int
        :rtype: int
        """
        return sum([x[1] for x in self.stack[: K]])

    def reset(self, playerId):
        """
        :type playerId: int
        :rtype: None
        """
        i = 0
        while i < len(self.stack):
            if self.stack[i][0] == playerId:
                del self.stack[i]
                break
            i += 1
